import Vue from 'vue'
import Vuex from './vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  modules:{
    a: {
      state:{
        name:'A module'
      },
      mutations:{
        syncChange() {
          console.log('A syncChange')
        }
      },
      modules: {
        dd: {
          state:{
            name:'DD module'
          },
          mutations:{
            syncChange() {
              console.log('DD syncChange')
            }
          },
          modules: {
            FF: {
              state:{
                name:'FF module'
              },
              mutations:{
                syncChange() {
                  console.log('FF syncChange')
                }
              }
            },
          }
        },
      }
    },
    b: {
      state:{
        name:'B module'
      },
      mutations:{
        syncChange() {
          console.log('B syncChange')
        }
      },
      actions: {
        asyncChange() {
          setTimeout(() => {
            console.log('11111111111111111111111111')
          }, 3000)
        }
      },
      modules: {
        c: {
          state:{
            name:'C module'
          },
          mutations:{
            syncChange() {
              console.log('C syncChange')
            }
          }
        },
      }
    }
  },
  state: {
    name: 'hello world',
    age: 23
  },
  getters: {
    myAge(state) {
      return state.age + 20
    }
  },
  mutations: {
    syncChange(state, payload) {
      state.age += payload
    }
  },
  actions: {
    asyncChange({ commit }, payload) {
      setTimeout(() => {
        commit('syncChange', payload)
      }, 3000)
    }
  }
})

export default store